<?php

namespace app\api\controller;

use app\api\model\Common;
use frame\lib\Db;

class Index extends Base
{
    public function index()
    {
        Common::statistics($this->user_id);
    }

    // 接口配置 
    public function conf()
    {
        $confGet = @$_GET['conf'];
        $conf = Db::name('config')->where(['user_id' => $this->user_id])->find()['conf'];
        $conf = json_decode($conf, true);
        $data = [
            'new' => $conf['new'],
            'update_new' => $conf['update_new'],
            'version' => $conf['version'],
            'downloadLink' => $conf['downloadLink'],
            'sign_three' => $conf['sign_three'],
            'sign_seven' => $conf['sign_seven'],
            'sign_fifteen' => $conf['sign_fifteen'],
        ];
        if (!empty($confGet)) {
            if (!array_key_exists($confGet, $data)) error('参数不存在');
            echo $data[$confGet];
        } else {
            success($data);
        }
    }
    public function feedback()
    {
        $content = @$_POST['content'];
        $uid = $this->uid;
        if (!empty($content)) {
            $data = [
                'uid' => $uid,
                'user_id' => $this->user_id,
                'content' => preventXSS($content),
                'create_time' => getTime()
            ];
            request_limit('feedback', "uid = $uid", 10, "请 10 后再来反馈哦 !感谢您的支持");
            $res = Db::name('feedback')->insert($data);
            if ($res) {
                success();
            }
            error();
        }
    }
    public function file()
    {
        $name = @$_GET['name'];
        $data = Db::name('file')->field(['id','content','file_name'])->where(['file_name' => $name])->find();
        if ($data) success($data);
        error('文档不存在');
    }
}
